
#include "res_t.h"
res_t::res_t():spr(NULL),resX(0),resY(0),resW(0),resH(0),showX(0),showY(0)
{
}


res_t::~res_t()
{
	safe_delete(spr);
}


int res_t::init( const string & picFile, int showX, int showY, int resW, int resH )
{	
	this->picFile = picFile;
	this->showX = showX;
	this->showY = showY;
	this->resW = resW;
	this->resH = resH;
	HTEXTURE tex = hgeResMgr::GetSingleton()->GetTexture(picFile.c_str());
	if (tex) spr = new hgeSprite( tex, (float)resX, (float)resY, (float)resW, (float)resH );
	else return 0;
	return 1;
}


int res_t::draw()
{
	return safeRender( spr, (float)showX, (float)showY );
}


int res_t::update()
{
	return 1;
}


void res_t::reRect( int x, int y, int w, int h )
{
	if ( x==resX && y==resY && w==resW && h==resH ){ return; }
	resX = x;
	resY = y;
	resW = w;
	resH = h;
	spr->SetTextureRect( (float)resX, (float)resY, (float)resW, (float)resH );
}


void res_t::reRect( int x, int y )
{
	if ( x==resX && y==resY ){ return; }
	resX = x;
	resY = y;
	spr->SetTextureRect( (float)resX, (float)resY, (float)resW, (float)resH );
}